package com.lagou;

import com.lagou.bean.Resume;
import com.lagou.repository.ResumeRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import java.util.List;

@SpringBootApplication
public class MongoRepositoryMain {
    public static void main(String[] args) {
        ApplicationContext  applicationContext = SpringApplication.run(MongoRepositoryMain.class,args);
//        ResumeRepository  resumeRepository = applicationContext.getBean(ResumeRepository.class);
//        /* System.out.println(resumeRepository.findAll());
//        System.out.println(resumeRepository.findByNameEquals("zhangsan"));
//        System.out.println(resumeRepository.findByNameAndExpectSalary("zhangsan",25000)); */
//        Resume resume  = new Resume();
//        resume.setName("chengdaotest");
//        resume.setExpectSalary(1);
//        resume.setCity("bj");
//        resumeRepository.save(resume);

        System.out.println("=====================================start");
        testSave(applicationContext);
        testFind(applicationContext);
        System.out.println("=====================================end");
    }

    public static void testSave(ApplicationContext  applicationContext){
        ResumeRepository  resumeRepository = applicationContext.getBean(ResumeRepository.class);

        Resume resume  = new Resume();
        resume.setName("lg_test3");
        resume.setExpectSalary(3);
        resume.setCity("sz");
        resumeRepository.save(resume);
    }

    public static void testFind(ApplicationContext  applicationContext){
        ResumeRepository  resumeRepository = applicationContext.getBean(ResumeRepository.class);

        List<Resume> all = resumeRepository.findAll();
        for(Resume model : all){
            System.out.println(model);
        }

    }
}
